﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Logistics_Service.DTO;
using System.Data;

namespace Logistics_Service.DAO
{
    public class TinhTrangXeDAO
    {
        public TinhTrangXeDTO[] DanhSachTinhTrangXe()
        {
            TinhTrangXeDTO[] arr;
            string query = string.Format("select * from TinhTrangXe");
            DataProvider provider = new DataProvider();
            DataTable dt = provider.ExecuteQuery(query);
            int n = dt.Rows.Count;
            arr = new TinhTrangXeDTO[n];
            for (int i = 0; i < n; i++)
            {
                object ttx = GetDataFromDataRow(dt, i);
                arr[i] = (TinhTrangXeDTO)ttx;
            }
            return arr;
        }
        protected object GetDataFromDataRow(DataTable dt, int i)
        {
            TinhTrangXeDTO ttx = new TinhTrangXeDTO();
            ttx.Ma = dt.Rows[i]["Ma"].ToString();
            ttx.Ten = dt.Rows[i]["Ten"].ToString();            
            ttx.DaXoa = bool.Parse(dt.Rows[i]["DaXoa"].ToString());
            return (object)ttx;
        } 
        public static TinhTrangXeDTO Get(String ma)
        {
            string query = "select*from TinhTrangXe Where Ma = '" + ma + "'";
            DataProvider provider = new DataProvider();
            DataTable dt = provider.ExecuteQuery(query);

            TinhTrangXeDTO ttx = new TinhTrangXeDTO();
            ttx.Ma = ma;
            ttx.Ten=dt.Rows[0]["Ten"].ToString();
            ttx.DaXoa = bool.Parse(dt.Rows[0]["DaXoa"].ToString());

            return ttx;
        }
    }
}